import { Form, Input, Button, message } from 'antd'
import {
UserOutlined,
LockOutlined
} from '@ant-design/icons';
import { adminLoginFn } from '../../api/user';
import { useAppDispatch } from '../../store/hooks';
import { changeAdminName, changeCheckedkeys, changeLoginState, changeRole, changeToken } from '../../store/modules/user';
import {  useLocation, useNavigate  } from 'react-router-dom';

export const Index = (props) => {
const dispatch = useAppDispatch()

const navigate = useNavigate()

const onFinish = (values) => {
 // console.log(values)
 adminLoginFn(values).then(res => {
   console.log(res.data)
      localStorage.setItem("adminname",res.data[0].adminname)
      console.log(123);
      navigate("/",{replace:false})
 })
}
return (
 <div id='components-form-demo-normal-login'>
   <Form
     name="normal_login"
     className="login-form"
     initialValues={{ remember: true }}
     onFinish={onFinish}
   >
     <h1 >酒店后台管理系统</h1>
     <Form.Item
       name="adminname"
       rules={[{ required: true, message: '请输入管理员账户!' }]}
     >
       <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="管理员账户" allowClear 
       style={{
         backgroundColor: 'rgb(255, 255, 255,0.3)'
       }}/>
     </Form.Item>
     <Form.Item
       name="password"
       rules={[{ required: true, message: '请输入密码!' }]}
     >
       <Input
         prefix={<LockOutlined className="site-form-item-icon" />}
         type="password"
         placeholder="密码"
         allowClear
         style={{
          backgroundColor: 'rgb(255, 255, 255,0.3)'
        }}
       />
     </Form.Item>
 
     <Form.Item>
       <Button type="primary" htmlType="submit" className="login-form-button">
         登 录
       </Button>
     </Form.Item>
   </Form>
 </div>
)
}